package com.bw.session.init;


import com.alibaba.fastjson.JSONObject;
import com.bw.session.domain.po.SessionPO;
import com.bw.session.mapper.SessionMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class AppDemo implements ApplicationRunner {

    @Autowired
    private SessionMapper sessionMapper;
    @Autowired
    private StringRedisTemplate redisTemplate;

    @Override
    public void run(ApplicationArguments args) throws Exception {
        List<SessionPO> allSessions = sessionMapper.getAllSessions(null);
        redisTemplate.opsForValue().set("session:list", JSONObject.toJSONString(allSessions));
    }
}
